﻿using AiXiu.BLL;
using AiXiu.Common;
using AiXiu.IBLL;
using AiXiu.Model;
using System;
using System.Web.UI;

namespace AiXiu.WebSite
{
    public partial class Register : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            // 判断是否通过表单验证
            if (Page.IsValid)
            {
                //验证码校验Session["Captcha"]
                string code = txtCaptcha.Text;
                string captcha = Session["captcha"].ToString();
                if (code != captcha)
                {
                    this.Alert("codefail", "验证码输入有误！");
                }
                else
                {
                    //获取页面输入信息
                    TBLogins logins = new TBLogins();
                    logins.UserName = txtUserName.Text;
                    logins.MobileNumber = txtMobileNumber.Text;
                    logins.Password = txtPassword.Text;

                    //调用UserBLL中的注册方法
                    IUserBLL userBLL = new UserBLL();
                    OperResult operResult = userBLL.Register(logins);
                    //注册成功，弹框并跳转this.AlertAndRedirect
                    if (operResult.StatusCode == StatusCode.Succeed)
                    {
                        this.AlertAndRedirect("registersuccess", "注册成功", "Login.aspx");
                    }
                    else
                    {
                        //注册失败，弹框提示
                        this.Alert("registerfail", operResult.Message);
                    }
                }
                

            }
        }
    }
}